var ctxPath = "/education";

/**
 * Javascript API调用ActionSheet
 */
!function ($) {

    var search = window.location.search.substring(8);
    var generation, country, name;

    if("" != search){
        var searchType = search.split(",")[0];
        if("generation" == searchType){
            generation = search.split(",")[1];
        }else if("country" == searchType){
            country = search.split(",")[1];
        }else if("name" == searchType){
            name = search.split(",")[1];
            //decodeURIComponent中文转码
            $("#productName").val(decodeURIComponent(name));
        }

        ajaxSearch();
    }

    $('#productName').bind('search', function () {
        ajaxSearch();

        this.blur();
    });

    function ajaxSearch(){
        $.ajax({
            url:  ctxPath + '/wx/api/product/queryStudyToursProducts',
            data: {'name' : decodeURIComponent($("#productName").val()), 'generation' : generation, 'country' : country, 'page' : 1, 'limit' : 20},
            type: 'post',
            dataType: 'json',
            success: function (result) {
                if(result.returnCode == 0) {
                    $('article').empty();
                    $.each(result.data, function(index, ele){
                        $('article').append("<a href=\"/education/wx/studyToursProductDetail.html?id=" + ele.id + "\" class=\"list-item\">" +
                            "<div class=\"list-img\"><img src=\"" + ele.showImage + "\" height='112' width='112'/></div>" +
                            "<div class=\"list-mes\"> <h3 class=\"list-title\">" + ele.name + "</h3><div class=\"list-mes-item\"><div>" +
                            "<span class=\"list-price\">¥" + ele.price + "</span></div></div></div></a>");
                    });
                } else {
                    alert("搜索错误！");
                }
            }
        });
    }

}(jQuery);